package com.zhike.b2b.company;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import com.saas.biz.custwebmgr.CustWebMgr;
import com.zhike.b2b.base.BaseAction;
import com.zhike.b2b.model.CompanyVo;

@Controller
public class CompanyAction extends BaseAction {

	public String createSite(@RequestParam("ids")String ids,HttpServletRequest request)
	{
        String msg = "";
		String custids = request.getParameter("ids")!=null?request.getParameter("ids").toString():"";
		String buildertype = request.getParameter("buildertype")!=null?request.getParameter("buildertype").toString():"";
		if(!"".equals(buildertype)){
			
			if("1".equals(buildertype)){//选定生成
					String[] atrs = custids.split("!");
					StringBuffer sb = new StringBuffer();
					for(int i=0;i<atrs.length;i++){
						if(i!=0){
							sb.append(",'"+atrs[i].toString()+"'");
						}else{
							sb.append("'"+atrs[i].toString()+"'");
						}
					}
					List<CompanyVo> coms = cs.getCompany(sb.toString());
				 	for(CompanyVo cv : coms){
				 		String tcustid = cv.getCustId();
				 		String tcust_name = cv.getCustName();
				 		int flag = new CustWebMgr().builderHTML(tcustid,request.getRealPath("/"));
				 		if(flag == 1){
				 			msg = "<a target='_blank' href='/company/web/"+tcustid+"/templates/index.html'>["+tcust_name + "]</a>企业站生成完毕！<br>";
				 		}else{
				 			msg = "<font color='red' >"+tcust_name + "企业站生成有误！</font>";
				 		}
				   }
				}else if("2".equals(buildertype)){
					List<CompanyVo> coms = cs.queryCompanies("", "", "", "");
				 	for(CompanyVo cv : coms){
				 		String tcustid = cv.getCustId();
				 		String tcust_name = cv.getCustName();
				 		int flag = new CustWebMgr().builderHTML(tcustid,request.getSession().getServletContext().getRealPath("/"));
				 		if(flag == 1){
				 			msg = "<a target='_blank' href='/company/web/"+tcustid+"/templates/index.html'>["+tcust_name + "]</a>企业站生成完毕！<br>";
				 		}else{
				 			msg = "<font color='red' >"+tcust_name + "企业站生成有误！</font>";
				 		}
				 	}
				}else{
					msg = "参数有误！";
				}
			}else{
				msg = "buildertype参数不能为空！";
			}

		return "";
	}
}
